// component/home/com-new-house-item/com-new-house-item.js
const defaultImg = '/images/defaultImgSmall.jpg';
import api from "../../../common/api.js";

Component({
  /**
   * 组件的配置
   */
  options: {
    styleIsolation: 'isolated',
    pureDataPattern: /^_/,
  },

  /**
   * 组件的属性列表
   */
  properties: {
    model: {
      type: Object,
      value: {}
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    defaultImg: '',
  },

  /**
   * 组件的方法列表
   */
  methods: {
    handleImgError() {
      this.setData({
        defaultImg: defaultImg
      })
    },

    onClick() {
      this.triggerEvent('jump')
    },

    handleShare(e) {
      this.triggerEvent("onhandleshare", this.data.model.id)
    },

    handleVisit(e) {
      wx.navigateTo({
        url: '/pages/visitors/visitors?id=' + this.data.model.id,
      })
    },

    outHouse() {
      wx.navigateTo({
        url: `/pages/house/houseUndercarriage/houseUndercarriage?delId=${this.data.model.id}&style=new`
      });
    },

    putHouse() {
      const {
        id
      } = this.data.model || {}
      wx.showModal({
        title: '提示',
        content: '是否重新上架房源?',
        success: (res) => {
          if (res.confirm) {
            api.downNewHouseById({
              delId: id,
              state: "AVAILABLE",
              invalidType: 1,
              reasonCode: '',
            }, (result) => {
              if (result && result.data && result.data.isSuccess) {
                this.triggerEvent('refresh')
              } else {
                wx.showToast({
                  icon: 'none',
                  title: '上架失败，请稍后再试',
                })
              }
            });
          }
        }
      })
    },

  }


})